package com.tanhua.server.controller;

import com.tanhua.common.utils.Cache;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBastController {

    @Autowired
    private TodayBestService todayBestService;
    @GetMapping("todayBest")
    @Cache
    private ResponseEntity<TodayBest> queryTodayBest(){
        TodayBest todayBest= null;
        try {
            todayBest = this.todayBestService.queryTodayBest();
            if (null!=todayBest) {
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
           log.error("今日佳人信息获取失败!!userId="+UserThreadLocal.get().getId(),e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("今日佳人信息查询失败!!").build();
    }

    @GetMapping("recommendation")
    public ResponseEntity<PageResult> queryRecommendation(
                                                          RecommendUserQueryParam queryParam){
        try {
            PageResult pageResult = this.todayBestService.queryRecommendation(queryParam);
            if (null!=pageResult) {
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            log.error("今日推荐人信息获取失败!! userId="+UserThreadLocal.get().getId(),e);
        }


        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
